import request from '@/libs/request'

export function userInfo(){
  return request({
    url: '/sys/user/info',
    method: 'get'
  })
}
export function registerUser(data){
  return request({
    url:'/sys/user/register',
    method:'post',
    data
  })
}
/**
 * 查询用户列表
 * @param data
 * @returns {*}
 */
export function queryUserList(data){
  return request({
    url:'/sys/user',
    method:'get',
    params:data
  })
}

/**
 * 唯一性校验
 * @param param
 * @returns {*}
 */
export function checkUniqueness(param){
  return request({
    url:'/sys/user/checkUniqueness',
    method:'get',
    params:param
  })
}

/**
 * 添加用户
 * @param data
 * @returns {*}
 */
export function saveUser(data){
  return request({
    url:'/sys/user',
    method:'post',
    data
  })
}

/**
 * 修改用户
 * @param data
 * @returns {*}
 */
export function updateUser(data){
  return request({
    url:'/sys/user',
    method:'put',
    data
  })
}
export function deleteUser(ids){
  return request({
    url:'/sys/user/deleteUser',
    method:'delete',
    params:{ids:ids}
  })
}

/**
 * 校验用户是否存在
 * @param value
 * @returns {*}
 */
export function checkUserExists(value){
  return request({
    url:`/sys/user/checkUserExists`,
    method:'post',
    params:{value:value}
  })
}

/**
 * 校验原密码
 * @param password
 * @returns {AxiosPromise}
 */
export function checkPassword(password){
  return request({
    url:'/sys/user/checkPassword',
    method:'post',
    params:{password}
  })
}
export function updatePasswd(password){
  return request({
    url:'/sys/user/updatePasswd',
    method:'post',
    params:password
  })
}

export function resetPasswd(data){
  return request({
    url:'/sys/user/resetPasswd',
    method:'post',
    data
  })
}
/**
 * 禁用用户
 * @param userId
 * @returns {*}
 */
export function disableUser(userId){
  return request({
    url:`/sys/user/disable/${userId}`,
    method:'post'
  })
}
/**
 * 启用
 * @param userId
 * @returns {*}
 */
export function enableUser(userId){
  return request({
    url:`/sys/user/enable/${userId}`,
    method:'post'
  })
}
export const getUnreadCount = () => {
  return request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
